package com.trigsoft.applist;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import com.trigsoft.utils.PrefUtil;
import com.trigsoft.utils.ProgressDialogUtils;

public class ImportTask extends AsyncTask<Void, Void, Boolean>
{
	private Context context;
	private ProgressDialog mProgressDialog;
	private String errMsg = "";

	public ImportTask(Context context)
	{
		this.context = context;
	}

	@Override
	protected Boolean doInBackground(Void... arg0)
	{
		// TODO Auto-generated method stub
		try
		{
			return PrefUtil.importPref(context);
		} catch (FileException e)
		{
			// TODO Auto-generated catch block
			errMsg = e.getMessage() + "，";
			return false;
		}
	}

	@Override
	protected void onPostExecute(Boolean result)
	{
		mProgressDialog.dismiss();
		if (result)
		{
			((RefreshActivity) context).setView();
			Toast.makeText(context, R.string.importSuccess, Toast.LENGTH_SHORT).show();
		} else
			Toast.makeText(context, errMsg + context.getString(R.string.importFailure), Toast.LENGTH_SHORT).show();

	}

	@Override
	protected void onPreExecute()
	{
		mProgressDialog = ProgressDialogUtils.show(context, R.string.import_setting_title);
	}
}
